define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'warehousing/index' + location.search,
                    add_url: 'warehousing/add',
                    del_url: 'warehousing/del',
                    multi_url: 'warehousing/multi',
                    table: 'warehousing',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'nickname', title: '员工姓名',operate:false},
                        {field: 'order_no', title: __('Order_no')},
                        {
                            field: 'name',operate:false, title: '商品名称',formatter:function(value,row,index){
                               
                               
                                var goods_name = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    goods_name += row.good_json_text[i]['name']+'<br><br>';
                                }
                                return goods_name;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '渠道来源',formatter:function(value,row,index){
                                var channel_source = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    channel_source += row.good_json_text[i]['channel_source']+'<br><br>';
                                }
                                return channel_source;
                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '批号',formatter:function(value,row,index){
                               
                               
                                var batch_number = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    batch_number += row.good_json_text[i]['batch_number']+'<br><br>';
                                }
                                return batch_number;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '类别',formatter:function(value,row,index){
                                var type = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    type += row.good_json_text[i]['type']+'<br><br>';
                                }
                                return type;
                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '货物位置',formatter:function(value,row,index){
                                var location = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    location += row.good_json_text[i]['location']+'<br><br>';
                                }
                                return location;
                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '条形码',formatter:function(value,row,index){
                                var codebar = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    codebar += row.good_json_text[i]['codebar']+'<br><br>';
                                }
                                return codebar;
                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '货号',formatter:function(value,row,index){
                                var huohao = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    huohao += row.good_json_text[i]['huohao']+'<br><br>';
                                }
                                return huohao;
                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '免税',formatter:function(value,row,index){
                                var mianshui = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    mianshui += row.good_json_text[i]['mianshui']+'<br><br>';
                                }
                                return mianshui;
                            }
                        },
                        
                        {
                            field: 'good_json',operate:false, title: '入库数量',formatter:function(value,row,index){
                               
                               
                                var num = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    num += row.good_json_text[i]['num']+'<br><br>';
                                }
                                return num;

                            }
                        },
                        
                        {
                            field: 'good_json',operate:false, title: '已入库数量',formatter:function(value,row,index){
                               
                               
                                var in_num = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    in_num += row.good_json_text[i]['in_num']+'<br><br>';
                                }
                                return in_num;

                            }
                        },
                        {
                            field: 'good_json',operate:false, title: '未入库数量',formatter:function(value,row,index){
                               
                               
                                var not_in_num = '';
                                for (var i = row.good_json_text.length - 1; i >= 0; i--) {
                                    not_in_num += row.good_json_text[i]['not_in_num']+'<br><br>';
                                }
                                return not_in_num;

                            }
                        },
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});